// services/user_service.go

package services

import (
	db "pets.ser163.cn/database"
	"pets.ser163.cn/events"
	"pets.ser163.cn/model"
)

func GetAllUsers() ([]model.Users, error) {
	var users []model.Users
	result := db.DB.Find(&users)
	return users, result.Error
}

func CreateUser(user *model.Users) error {
	result := db.DB.Create(user)
	if result.Error == nil {
		// 发布用户创建事件
		events.EventBusInstance.Publish("user:created", map[string]interface{}{
			"username": user.Username,
		})
	}
	return result.Error
}
